package com.yxjwzpx.management.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.yxjwzpx.management.domain.ShipType;
import com.yxjwzpx.management.service.IShipTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 船舶类型Controller
 * 
 * @author yxjwzpx
 * @date 2025-04-08
 */
@RestController
@RequestMapping("/management/type")
public class ShipTypeController extends BaseController
{
    @Autowired
    private IShipTypeService shipTypeService;

    /**
     * 查询船舶类型列表
     */
    @PreAuthorize("@ss.hasPermi('management:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShipType shipType)
    {
        startPage();
        List<ShipType> list = shipTypeService.selectShipTypeList(shipType);
        System.out.println("查询船舶类型成功！");
        return getDataTable(list);
    }

    /**
     * 导出船舶类型列表
     */
    @PreAuthorize("@ss.hasPermi('management:type:export')")
    @Log(title = "船舶类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShipType shipType)
    {
        List<ShipType> list = shipTypeService.selectShipTypeList(shipType);
        ExcelUtil<ShipType> util = new ExcelUtil<ShipType>(ShipType.class);
        util.exportExcel(response, list, "船舶类型数据");
    }

    /**
     * 获取船舶类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('management:type:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return success(shipTypeService.selectShipTypeByTypeId(typeId));
    }

    /**
     * 新增船舶类型
     */
    @PreAuthorize("@ss.hasPermi('management:type:add')")
    @Log(title = "船舶类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShipType shipType)
    {
        return toAjax(shipTypeService.insertShipType(shipType));
    }

    /**
     * 修改船舶类型
     */
    @PreAuthorize("@ss.hasPermi('management:type:edit')")
    @Log(title = "船舶类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShipType shipType)
    {
        return toAjax(shipTypeService.updateShipType(shipType));
    }

    /**
     * 删除船舶类型
     */
    @PreAuthorize("@ss.hasPermi('management:type:remove')")
    @Log(title = "船舶类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(shipTypeService.deleteShipTypeByTypeIds(typeIds));
    }
}
